home *** CD-ROM | disk | FTP | other *** search
- PROGRAM fplot;
-
- CONST
- pi = 3.14159;
- {$I gemconst.pas}
-
- TYPE
- {$I gemtype.pas}
-
- VAR
- phi,theta : real;
- x,y,z : real;
- scalex,scaley,scalez : real;
- event,
- which,
- dummy,
- handle,
- wind_type : integer ;
- title : Window_Title ;
- c0,r0 : integer;
- msg : message_buffer;
-
- {$I gemsubs.pas}
-
- procedure f ( var x,y,z : real);
-
- begin
- y := sin(2*pi*sqrt(x*x+z*z))/6; {calculate y from x,z}
- end;
-
- procedure draw_f; {draw function on screen}
-
- var
- f : string[255];
-
- begin
- line_color(2);
- f := 'y := sin(2*pi*sqrt(x*x+z*z))/6;';
- draw_string(c0-3*length(f),195,f);
- draw_string(20,20,'Programmed by G. F. Sellars');
- draw_string(20,30,' with Oss Personal Pascal');
- end;
-
- procedure project(x,y,z : real; var c,r : integer); {3d to 2d}
-
- var
- d : real;
-
- begin
- d := scalez*z;
- c := round(scalex*(x+d))+c0;
- r := round(scaley*(y+d))+r0;
- end;
-
- PROCEDURE plot_curve;
-
- var
- c,r : integer;
-
- begin
- z := -1; {plot lines parallel to x axis}
- while z <= 1 do begin
- x := -1;
- f(x,y,z);
- project(x,y,z,c,r);
- move_to(c,r);
- while x <= 1 do begin
- f(x,y,z);
- project(x,y,z,c,r);
- line_to(c,r);
- x := x + 0.05;
- end;
- z := z + 0.05;
- end;
- x := -1; {plot lines parallel to z axis}
- while x <= 1 do begin
- z := -1;
- f(x,y,z);
- project(x,y,z,c,r);
- move_to(c,r);
- while z <= 1 do begin
- f(x,y,z);
- project(x,y,z,c,r);
- line_to(c,r);
- z := z + 0.05;
- end;
- x := x + 0.05;
- end;
- END;
-
- procedure axis(x0,y0,z0,x1,y1,z1 :real; name : char); {draw x,y, or z axis}
-
- var
- c,r : integer;
-
- begin
- project(x0,y0,z0,c,r);
- move_to(c,r);
- project(x1,y1,z1,c,r);
- line_to(c,r);
- project(1.1*x1,1.1*y1,1.1*z1,c,r);
- draw_string(c,r,name);
- end;
-
- procedure init;
-
- var
- i,c,r,w,h: integer;
- wr,hr : real;
-
- begin
- handle := New_Window(0,title,0,0,0,0);
- Open_Window(handle,0,0,0,0);
- Work_Rect(handle,c,r,w,h);
- Set_Clip(c,r,w,h);
- Paint_Style(Solid);
- Paint_Color(White);
- Paint_Rect(c,r,w,h);
- c0 := (w-c) div 2; {c0,r0 = center of screen}
- r0 := (h-r) div 2;
- r0 := r0+16;
- wr := w-c; hr := h-r;
- scalex := wr/4;
- scaley := -hr/2.5;
- scalez := -1/2;
- Line_Color(2);
- text_color(2);
- axis(-1,0,0,1,0,0,'x');
- axis(0,-1,0,0,1,0,'y');
- axis(0,0,-2,0,0,2,'z');
- Line_Color(1);
- end;
-
- BEGIN
- IF Init_Gem >= 0 THEN BEGIN
- Hide_Mouse ;
- Begin_Update ;
- init;
- plot_curve;
- draw_f;
- End_Update ;
- write(chr(7));
- repeat
- event := get_event(e_button | e_timer,1,1,1,
- 10,
- false,0,0,0,0,
- false,0,0,0,0,
- msg,dummy,dummy,dummy,dummy,dummy,dummy);
- until event & e_button <> 0; {until left mouse button clicked once}
- Show_Mouse ;
- Close_Window( handle ) ;
- Delete_Window( handle ) ;
- END;
- Exit_Gem ;
- END.
-